<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var nums = [12, 11, 16, 27, 9];
        var max = num[0];
        for (var i = 1; i < nums.length; i++) {
            if (max < nums[i]) {
                max = nums[i];
            }
        }
        console.log(max);

        // 如何获取最大值 对应的索引
        var age = [12, 16, 10, 8, 9];
        var maxIndex = 0; // 代表最大值对应的 索引
        for (var i = 1; i < age.length; i++) {
            // age[maxIndex] 代表当前的最大值
            if (age[maxIndex] < age[i]) {
                maxIndex = i;
            }
        }
        console.log(maxIndex);
    </script>
</body>

</html>